/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author anas
 */
public class Client extends javax.swing.JInternalFrame {

        Connection conn =null;
        PreparedStatement ps =null;
        
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        
    public Client() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        CIN_Client = new javax.swing.JTextField();
        Nom_Client = new javax.swing.JTextField();
        Prenom_Client = new javax.swing.JTextField();
        Numero_Tele_Client = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        Email_Client = new javax.swing.JTextField();
        Metier_Client = new javax.swing.JTextField();
        Nombre_Enfant_Client = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        oui = new javax.swing.JRadioButton();
        non = new javax.swing.JRadioButton();
        Date_Naissance_Client = new com.toedter.calendar.JDateChooser();

        setMaximizable(true);
        setResizable(true);

        jLabel2.setText("Nom :");

        jLabel3.setText("Prénom :");

        jLabel4.setText("N° Tele : ");

        jLabel1.setText("CIN  :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(295, 295, 295)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(66, 66, 66)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(CIN_Client)
                    .addComponent(Nom_Client)
                    .addComponent(Prenom_Client)
                    .addComponent(Numero_Tele_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(479, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(CIN_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(46, 46, 46)
                        .addComponent(jLabel2))
                    .addComponent(Nom_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(56, 56, 56)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(Prenom_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(65, 65, 65)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(Numero_Tele_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(95, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(" Obligatoire Infos", jPanel1);

        jLabel5.setText("Email :");

        jLabel6.setText("Marié : ");

        jLabel7.setText("Métier :");

        jLabel8.setText("Date de Naissance :");

        Metier_Client.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Metier_ClientActionPerformed(evt);
            }
        });

        jLabel9.setText("Nombre d'enfants :");

        jLabel10.setText("Annuler");

        jLabel11.setText("Enregistrer");
        jLabel11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel11MouseReleased(evt);
            }
        });

        oui.setText("Oui");

        non.setText("Non");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(164, 164, 164)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(249, 249, 249)
                        .addComponent(jLabel10)
                        .addGap(99, 99, 99)
                        .addComponent(jLabel11)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(87, 87, 87)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel8))
                                .addGap(99, 99, 99)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(Email_Client, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                            .addComponent(Metier_Client)
                            .addComponent(Nombre_Enfant_Client)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(oui)
                                .addGap(18, 18, 18)
                                .addComponent(non))
                            .addComponent(Date_Naissance_Client, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(410, 410, 410))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(Email_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(oui)
                    .addComponent(non))
                .addGap(33, 33, 33)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(Metier_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(Date_Naissance_Client, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(Nombre_Enfant_Client, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(30, 30, 30))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(21, 21, 21))))
        );

        jTabbedPane1.addTab("Optionnel infos", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Metier_ClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Metier_ClientActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Metier_ClientActionPerformed

    private void jLabel11MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel11MouseReleased
        
        String cin=CIN_Client.getText();
        String nom=Nom_Client.getText();
        String prenom=Prenom_Client.getText();
        String Ntel=Numero_Tele_Client.getText();
        String email=Email_Client.getText(); 
        String metier= Metier_Client.getText();      
           // java.util.Date datenaiss=Date_Naissance_Client.getDate();
        String nbrenf=Nombre_Enfant_Client.getText();  
        
        
       String requete="INSERT INTO CLIENT (CIN_CLIENT,NOM,PRENOM,NUMERO_TELE,EMAIL,SITUATION,DATE_NAISSANCE,METIER,NOMBRE_ENFANTS) VALUES (?,?,?,?,?,?,?)";
       String requete2="INSERT INTO CHAMBRE (CIN_CLIENT) VALUES (?)";
       String requete3="INSERT INTO PAIEMENT (CIN_CLIENT) VALUES (?)";
       
        String marier ="";
            if(oui.isSelected())
            {
                marier ="oui";
            }
            else if(non.isSelected()){
                
                marier ="non";
            }
            else{
                JOptionPane.showMessageDialog(null,"Error");
            }
       
       
       try {
            PreparedStatement ps =conn.prepareStatement(requete);
            ps.setString(1,cin);
            ps.setString(2,nom);
            ps.setString(3,prenom);
            ps.setString(4,Ntel);
            ps.setString(5,marier);
            ps.setString(6,((JTextField)Date_Naissance_Client.getDateEditor().getUiCompenent()).getText());
            ps.setString(7,nbrenf);
              
        }
       catch (SQLException | HeadlessException e) 
        {
            JOptionPane.showMessageDialog(null,e.getMessage());
        } 
       
       //POUR LA 2 EME REQUETE
       try 
       {
           PreparedStatement ps2 =conn.prepareStatement(requete2);
            ps2.setString(1,cin);
       }
        catch (SQLException | HeadlessException e)
        {
            JOptionPane.showMessageDialog(null,e.getMessage()); 
        }
       //POUR LA 3 EME REQUETE
       
        try 
       {
           PreparedStatement ps3 =conn.prepareStatement(requete3);
            ps3.setString(1,cin);
       }
        catch (SQLException | HeadlessException e)
        {
            JOptionPane.showMessageDialog(null,e.getMessage()); 
        }
       
       
        
        
        
        
    }//GEN-LAST:event_jLabel11MouseReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CIN_Client;
    private com.toedter.calendar.JDateChooser Date_Naissance_Client;
    private javax.swing.JTextField Email_Client;
    private javax.swing.JTextField Metier_Client;
    private javax.swing.JTextField Nom_Client;
    private javax.swing.JTextField Nombre_Enfant_Client;
    private javax.swing.JTextField Numero_Tele_Client;
    private javax.swing.JTextField Prenom_Client;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JRadioButton non;
    private javax.swing.JRadioButton oui;
    // End of variables declaration//GEN-END:variables
}
